<?php
	session_start();
	
	if( $_SESSION['reg_remember'] == "on" ){
		require_once("inc/encrypt.php");
		//langsung psang cookie, ntar bner gk nya di cek x_-x
		setcookie("hashlogin", enc_hash($_SESSION['reg_uname']), time()+60*60*24*100, "/");
		setcookie("hashremember", enc_hash(enc_hash($_SESSION['reg_upass'])), time()+60*60*24*100, "/");
		$_SESSION['reg_remember'] = null;
		$_SESSION['reg_upass'] = null;
	}else{
		$_SESSION['reg_upass'] = null;
	}
	//nanti bikin protect buat admin
	if (!isset($_SESSION["reg_login"]) || !isset($_SESSION["reg_uname"]) || !isset($_SESSION["reg_level"]) || ( !isset($_SESSION["reg_jurusan"]) && $_SESSION["reg_level"] < 2 ) ){
		if( (isset($_COOKIE['hashlogin']) && isset($_COOKIE['hashremember'])) ){
			/* Redirect to a different page in the current directory that was requested */
			$host  = $_SERVER['HTTP_HOST'];
			$uri   = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
			$extra = 'verify.php'; //awalnya pngen verify lagi.. coba kyk fb, lngsng login..
			header("Location: http://$host$uri/$extra");
			//if php doesn't work
			?>
				<meta http-equiv="refresh" content="0; url=<?php echo $extra; ?>">
				Klik <a href="<?php echo $extra; ?>">disini</a> apabila browser anda berhenti berjalan ...
			<?php
			exit;
		}else{
			session_destroy();
			$host  = $_SERVER['HTTP_HOST'];
			$uri   = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
			$extra = 'logout.php';
			header("Location: http://$host$uri/$extra");
			//if php doesn't work
			?>
				<meta http-equiv="refresh" content="0; url=<?php echo $extra; ?>">
				Klik <a href="<?php echo $extra; ?>">disini</a> apabila browser anda berhenti berjalan ...
			<?php
			exit;
		}
	}
	
	$reg_uname = $_SESSION["reg_uname"];
	$reg_level = $_SESSION["reg_level"];
	$reg_jurusan = $_SESSION["reg_jurusan"];
?>